<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .xx {
            width: 200px;
            height: 200px;
            color: red;
        }

        .nav {
            color: #000;
            background-color: pink;
        }
    </style>
</head>

<body>
    <img id="randomimg" src="" alt="随机图片" style="width:100%;height:100%;">
    <div class="xx">文字</div>
    <script>
        // const img = document.getElementById('randomimg');
        // const imgList = [
        //     '../学习/image/course01.png',
        //     '../学习/image/course02.png',
        //     '../学习/image/course03.png',
        //     '../学习/image/course04.png',
        // ];
        // const randomIndex = Math.floor(Math.random() * imgList.length);
        // img.src = imgList[randomIndex];

        //通过classList添加
        //1.获取元素
        const div = document.querySelector('.xx');
        //2.修改样式
        //2.1追加类 add() 类名不加点,并且是字符串
        div.classList.add('nav');
        //2.2删除类 remove() 类名不加点,并且是字符串
        // div.classList.remove('xx');
        //2.3切换类 toggle() 有还是没有啊，有就删除，没有就添加
        // div.classList.toggle('nav');
    </script>
</body>

</html>